package example.basic;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.mvel.MVEL;

public class ListExample {
	
	private static Log log = LogFactory.getLog(PropertyExample.class);
	
	public static void main(String[]args) {
		String result;
		Map vars = new HashMap();
		
		List<String> list = new ArrayList<String>();
		list.add("item0");
		list.add("item1");
		
		vars = new HashMap();
		vars.put("list", list);

		result = "\n"
			+ "The list is: \n" 
			+ "list[0]=" + (String)MVEL.eval("list[0]", vars) + "\n"
			+ "list.get(1)=" + (String)MVEL.eval("list.get(1)", vars);
		log.info(result);
		
		// =====================================================================
		User user1 = new User();
		user1.setName("kongxx");
		user1.setPassword("12345678");
		
		User user2 = new User();
		user2.setName("mandy");
		user2.setPassword("87654321");
		
		List<User> users = new ArrayList<User>();
		users.add(user1);
		users.add(user2);
		
		vars = new HashMap();
		vars.put("users", users);
		
		result = "\n"
			+ "The list is: \n" 
			+ "users[0].name=" + (String)MVEL.eval("users[0].name", vars) + "\n"
			+ "users[1].name=" + (String)MVEL.eval("users[1].name", vars);;
		log.info(result);
	}
}
